import React from 'react'
// ===================================================================== Temp
import TableModal from '#cpt/temp/TableModal'
// ===================================================================== global declare
const { $fn, $Lazy } = window
// ===================================================================== $Lazy
const $cache 				= $Lazy.file(()=>import('#private/cache-api'))
// ===================================================================== component
class Index extends React.Component{
	state = {
		data:[],
		pag: {},
		selectedKeys:[],
		selectedRows: [],
		forms : [
			{ label: '项目名称',		name: 'item_name',	width:300 },
			// 添加岗位搜索 2022/6/29 --马婷
			{ label: '岗位',		name: 'project_id',				type: 'select', loading:true },
		]
	}
	
	model = {}
	
	open = kind_id => {
		this.getSelect()
		this.modal.open()
		const { data } = this.state
		if(!$fn.hasArray(data)){
			this.kind_id = kind_id
			this.fetch()
		}else{
			this.table.resize()
		}
	}
	
	// 获取下拉数据
	getSelect = () => {
		const { forms } = this.state
		$cache.then( async f => {
			// 岗位
			$fn.setRow(forms, 'project_id',  await f.getCache({ api: 'gang_wei' }))
			this.setState({ forms })
		})
	}
	
	// paging
	fetch = () => $fn.fetch.call(this, 'kd-combin-project/select', {param:{ page_come: this.props.type }, paging:'get'})
	
	// 表单
	cols = [
		// { title: '项目代码', 	dataIndex: 'kind_code', 	width:150 },
		{ title: '项目名称', 	dataIndex: 'name', 			width:200 },
		{ title: '岗位', 		dataIndex: 'project_name', 	width:200 },
	]
	
	render(){
		let { api } = this.props
		api = api ? api : 'kd-market-rel/addbybatch'
		return TableModal.call(this,{ title: '添加项目明细', labelWidth:'s7', width:'60%', height:'80%', api,idStr:'value',
			// getSubmit: value => ({ json_params:JSON.stringify({ kind_id: this.kind_id, kind_rel_id: value })} )
			getSubmit: (keys, rows) => {
				let kind_rel_id = keys.map( v => ({ kind_rel_id:v } ))
				return { kind_id: this.kind_id, kind_rel_id }
			}
		})
	}
}

export default Index